/**
 * Created by Brook on 2019/2/25.
 */
(function(){
    const async = require('async');
    const webclient = require('nodegrass');
    const api_server = require('../webconfig.js').API_Server;

    const my_headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    };
    const _WebClient = function(command,send_data,callback){
        if(typeof (send_data) == 'object'){
            send_data = JSON.stringify(send_data)
        }
        const s_data = {api_data:send_data};
        webclient.post(api_server.host+command,function(data,status,headers){
            const temp_data = JSON.parse(data);
            callback(null,temp_data);
        },my_headers,s_data,'utf8').on('error', function(e) {
            console.log("web client error: " + e.message);
            callback(e.message);
        });
    }
    exports.WebClient = _WebClient;
    const _WebClient_get=function(command){

        webclient.get(command,function(data,status,headers){
            //var user_channel = JSON.parse(data);
            //callback(null, user_channel);

        },'utf8').on('error',function(e){
            console.log("web client error: " + e.message);
            //callback(e.message);
        });
    }
    exports.WebClient_get=_WebClient_get;
}).call(this);
